import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {//存储数据和状态
    SHOP: [],
    ding: []
  },
  mutations: {//修改状态
    aContents(state, data) {
      // state.SHOP.push(data);
      // arr.push(data);
      // var src=data.addSrc;
      var flag = false;//第一次直接添加
      state.SHOP.some(item => {
        //some:不创建新数组、不改变原数组、判断为true则马上return true
        //every:不创建新数组、不改变原数组、判断为false则马上return false
        if (item.shopSrc == data.shopSrc) {
          item.shopCount += data.shopCount;
          flag = true
          return true;//结束
        }
      })
      // state.SHOP=arr;
      if (!flag) {
        state.SHOP.push(data);
      }
      // console.log(state.SHOP);
    },
    aaContents(state, data) {
      // state.ding=[];
      var flag = false;//第一次直接添加
      state.ding.some(item => {
        if (item.shopSrc == data.shopSrc) {
          item.shopCount=data.shopCount;
          flag = true
          return true;//结束
        }
      })
      if (!flag) {
        state.ding.push(data);
      }
      // console.log(state.ding);
      if(data==200){
        state.ding=[];
      }
    }
  },
})
